package de.kai_morich.simple_usb_terminal;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.Button;
import android.Manifest;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentActivity;

/**
 * @author : liujiacheng
 * @Date ：2025/7/10 14:31
 * @Description ：
 **/
public class CameraxActivity extends FragmentActivity {
    private Button button;
    private Button scanButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_camerax); // 使用布局资源ID[1](@ref)

        // 手动绑定视图
        button = findViewById(R.id.button);
        scanButton = findViewById(R.id.scanButton);
        requestPermission();
        button.setOnClickListener(v -> intentTo(1));
        scanButton.setOnClickListener(v -> intentTo(2));
    }

    private void intentTo(int type) {
        if (type == 1) {
            startActivity(new Intent(this, ShootingActivity.class));
        } else if (type == 2) {
            startActivity(new Intent(this, ScanActivity.class));
        }
    }

    private void requestPermission() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            // 先判断有没有权限
            if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED &&
                    ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
//                writeFile();
            } else {
                ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 11);
            }
        } else {
//            writeFile();
        }
    }
    private void checkPermission(int type) {
//        PermissionX.init(this)    implementation 'com.permissionx.guolindev:permissionx:1.6.1'
//                .permissions(Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO)
//                .request((allGranted, grantedList, deniedList) -> {
//                    if (allGranted) {
//                        Toast.makeText(MainActivity.this, "grant success", Toast.LENGTH_SHORT).show();
//                        intentTo(type);
//                    } else {
//                        Toast.makeText(MainActivity.this, "refuse: " + deniedList, Toast.LENGTH_LONG).show();
//                    }
//                });
    }
}